package com.leetcode.partition5;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/24 8:46
 */
public class LC440字典序的第K小数字 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), k = Integer.parseInt(ss[1]);
        writer.write(findKthNumber(n, k) + "\n");
        writer.flush();
    }

    public static int findKthNumber(int n, int k) {
        int ans = 1;
        while (k > 1) {
            int cnt = getCnt(ans, n);
            if (cnt < k) {
                ans++;
                k -= cnt;
            } else {
                k--;
                ans *= 10;
            }
        }
        return ans;
    }

    private static int getCnt(int x, int limit) {
        String a = String.valueOf(x), b = String.valueOf(limit);
        int n = a.length(), m = b.length(), k = m - n, ans = 0;
        int u = Integer.parseInt(b.substring(0, n));
        for (int i = 0; i < k; i++) ans += Math.pow(10, i);
        if (u > x) ans += Math.pow(10, k);
        else if (u == x) ans += limit - x * Math.pow(10, k) + 1;
        return ans;
    }
}
